package com.fucking.great.context.util;

import com.fucking.great.context.single.AbstractPrototypeFactory;

/**
 * prototype bean工具的使用。
 * 多例原型工具类的使用。
 * @see AbstractPrototypeFactory
 */
public class PrototypeUtil {
    /**
     * 通过调用工厂的newPrototypeInstance()获得多例对象。
     * @see AbstractPrototypeFactory
     * @param factoryClass  多例工厂的class.
     * @param <T>           多例对象。
     * @return
     */
    public static <T> T getPrototypeInstance(Class<?> factoryClass){
        Object factoryBean = SingleUtil.getBean(factoryClass);
        Object instance = null;
        if(factoryBean instanceof AbstractPrototypeFactory){
            AbstractPrototypeFactory abstractPrototypeFactory = (AbstractPrototypeFactory) factoryBean;
            instance = abstractPrototypeFactory.newPrototypeInstance();
        }
        return (T) instance;
    }

}
